<?php
  // no direct access
  defined( '_JEXEC' ) or die( 'Restricted access' );
  jimport('joomla.application.component.controller');
  
  class SeasonController extends JController
  {  
    var $_name = 'season';
    function add(){
    
      $document =& JFactory::getDocument();
      $view = & $this->getView($this->_name, $document->getType());
      
      $view->setModel($this->getModel('division','divisionmodel'));
      parent::add();
    }
    
    function edit(){
      
      $document =& JFactory::getDocument();
      $view = & $this->getView($this->_name, $document->getType());
      
      $view->setModel($this->getModel('division','divisionmodel'));
      $view->setModel($this->getModel('seasondivision','seasondivisionmodel'));
      parent::edit();
    }
    
    function save()
    {
      $data = JRequest::get('POST');
       
      $model  = & $this->getModel($this->_name); 
      $season = $model->save($data);
      
      $season_division = $this->getModel('seasondivision','seasondivisionmodel');
      $season_division->renew_divisions($season->id, $data['divisions']);
       
      $redirectTo = JRoute::_('index.php?option='.JRequest::getVar('option').'&c='.JRequest::getVar('c'), false);
      $this->setRedirect($redirectTo,  ucfirst($this->_name) . ' Saved!');             
    }
  }
?>